<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>安全日常管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=0.3, user-scalable=0, minimum-scale=0, maximum-scale=5.0,user-scalable=yes">
    <link rel="stylesheet" type="text/css" href="/css/street/street.css"/>
    <link rel="stylesheet" type="text/css" href="/css/base.css"/>
    <link rel="stylesheet" href="/css/officialDocument/officialDocument.css">
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <style>
        .M-box3 a:hover {
            background: #2f80d1!important;
            margin: 0 3px!important;
            width: 29px!important;
            height: 29px!important;
            line-height: 29px!important;
            font-size: 12px!important;
        }
        .M-box .active, .M-box1 .active, .M-box2 .active, .M-box3 .active{
            background: #2f80d1!important;
            border: 1px solid #2b7fe0!important;
            margin: 0 3px!important;
            width: 29px!important;
            height: 29px!important;
            line-height: 29px!important;
            font-size: 12px!important;
        }
        .M-box a, .M-box1 a, .M-box2 a, .M-box3 a{
            margin: 0 3px!important;
            width: 29px!important;
            height: 29px!important;
            line-height: 29px!important;
            font-size: 12px!important;
        }
        .jump-ipt {
            margin: 0 3px;
            width: 28px;
            height: 26px;
            line-height: 26px;
            font-size: 12px;
        }
        .bordercolor b{
            margin-left: 10px;
        }
        .mainTitle{
            min-width:650px;
        }
        .mainTitleUl .bordercolor span{
            left: 14px !important;
        }
        ul li {
            padding: 0 !important;
        }
        .mainTitleUl .bordercolor label .picture ul{
            height: 76px;
        }
        .mainTitleUl .bordercolor span{
            margin-right: -2% !important;
        }
        .newBtn{
            background: url(/img/newjian.png) no-repeat;
            padding-left:5px;
            border:none
        }

    </style>
    <script src="/js/jquery/jquery-1.9.1.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/laydate/laydate.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jquery.form.min.js"></script>
    <script src="/lib/jquery-validate.js"></script>
    <script src="/lib/validate-mothods.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>
    <%--<script src="/js/compreCheck/checkTheInformation.js"></script>--%>
    <link rel="stylesheet" href="/css/biaodan.css">
</head>
<body >
<div class="header">
    <img src="/img/document/icon_myDispatch.png" class="fl" style="margin-top: 7px;">
    <div class="headertitle">安全日常管理</div>
    <div class="empty">
        <a href="javascript:void (0)" style="text-align: center;line-height: 28px;height: 28px;width: 70px;" data-type="1" class="newBtn btnData">新建</a>
    </div>
</div>


<div class="mainBg" style="background: #fff;display: none">
    <form action="" id="datasave" style="background: none">
        <input type="file"  onchange="filesTwo(this)" multiple="multiple" name="file"
               style="display: none"/>
        <input type="hidden" name="userId">
        <input type="hidden" name="said">
        <div class="mainTitle">
            <ul class="mainTitleUl">
                <li style="    padding-top: 18px;text-align: center;height: 61px;border-bottom: 1px solid #ddd"><span class="spanSize">安全日常管理记录表</span> </li>
                <li class="bordercolor clearfix">
                    <span style="border-bottom: 1px solid #fff">网格名称 <b style="color: red;vertical-align: middle;margin-left: 4px;">*</b></span>
                    <label>
                        <select onchange="subCommunityTwo(this)"  name="areaname" id="subCommunity">
                            <option value="">请选择</option>
                        </select>
                    </label>
                    <span>检查时间<b style="color: red;vertical-align: middle;">*</b></span>
                    <label>
                        <input type="text" name="checktime" placeholder="检查时间"
                               readonly="readonly" id="time" style="width:90%">
                    </label>
                </li>
                <li class="bordercolor clearfix">
                    <span style="border-bottom: 1px solid #fff;">检查人员姓名</span>
                    <label style="width: 30%;">
                        <input type="text" name="checkusername" placeholder="请填写检查人员姓名" style="background: #fcfcfc;    width: 80%;
    float: none;
    margin-top: 0px;">
                    </label>
                    <span style="border-bottom: 1px solid #fff;">检查单位名称</span>
                    <label style="width: 27%;">
                        <input type="text" name="checkunitname" placeholder="请填写检查单位名称" style="background: #fcfcfc;    width: 100%;
    float: none;
    margin-top: 0px;">
                    </label>
                </li>
                <%--<li class="bordercolor clearfix">--%>

                <%--</li>--%>
                <li class="bordercolor clearfix">
                    <span style="border-bottom: 1px solid #fff">隐患级别<b style="color: red;vertical-align: middle;">*</b></span>
                    <label>
                        <select name="problemlev" id="checkIds">
                            <option value="">请选择</option>
                            <option value="1">一般隐患</option>
                            <option value="2">突出隐患</option>
                            <option value="3">重大隐患</option>
                        </select>
                    </label>
                    <%--<label style="width: 50%;"></label>--%>
                    <span style="border-bottom: 1px solid #fff">整改情况<b style="color: red;vertical-align: middle;">*</b></span>
                    <label>
                        <select name="reformsituation" id="reformsituation" style="width: 95%;margin-left: -2px;">
                            <option value="">请选择</option>
                            <option value="1">当场整改</option>
                            <option value="2">整改中</option>
                            <option value="3">已整改</option>
                        </select>
                    </label>
                </li>
                <%--<li class="bordercolor clearfix">--%>
                    <%--<span style="border-bottom: 1px solid #fff">整改情况<b style="color: red;vertical-align: middle;">*</b></span>--%>
                    <%--<label>--%>
                        <%--<select name="reformsituation" id="reformsituation">--%>
                            <%--<option value="">请选择</option>--%>
                            <%--<option value="1">当场整改</option>--%>
                            <%--<option value="2">整改中</option>--%>
                            <%--<option value="3">已整改</option>--%>
                        <%--</select>--%>
                    <%--</label>--%>
                    <%--<label style="width: 50%;"></label>--%>
                <%--</li>--%>


                <li class="bordercolor clearfix">
                    <span style="border-bottom: 1px solid #fff;height: 144px;line-height: 144px">隐患简要描述</span>
                    <label style="width: 80%;height: 144px;">
                        <textarea name="problemdes" style="background: #fcfcfc"  placeholder="请填写隐患简要描述"></textarea>
                    </label>
                </li>

                <li class="bordercolor clearfix">
                    <span style="border-bottom: 1px solid #fff;height: 100px;line-height: 100px">整改前照片</span>
                    <label style="width: 80%;height: 100px;">
                        <div class="picture prevTwo" style="position: relative">
                            <input type="hidden" name="attachmentIdBefore">
                            <%--<a class="fl addPhotos" href="javascript:void (0)" ></a>--%>
                            <img class="fl addPhotos" style="    width: 60px;cursor: pointer;height: 60px;margin-top: 4px;margin-right: 7px;" src="/img/grid/addtupin.png" alt="添加照片">
                            <input type="hidden" name="attachmentNameBefore">

                            <ul class="fl" style="width:84%">
                                <li>
                                    <img src="/img/app/email.png" alt="">
                                    <b class="deleClear">x</b>
                                </li>
                            </ul>

                            <%--style="display:none;position: absolute;width: 68px;height: 30px;top: 27px;right: 5px;"--%>

                        </div>
                    </label>
                </li>
                <%--<li class="bordercolor clearfix">--%>
                    <%--<span style="border-bottom: 1px solid #fff;height: 144px;line-height: 144px">整改时限</span>--%>
                    <%--<label style="width: 80%;height: 144px;">--%>
                        <%--<input name="reformtime" style="background: #fcfcfc"  placeholder="请填写整改时限">--%>
                    <%--</label>--%>
                <%--</li>--%>
                <%--<li class="bordercolor clearfix">--%>
                    <%--<span style="border-bottom: 1px solid #fff;height: 144px;line-height: 144px">整改责任人</span>--%>
                    <%--<label style="width: 80%;height: 144px;">--%>
                        <%--<input name="reformuser" style="background: #fcfcfc"  placeholder="请填写整改责任人">--%>
                    <%--</label>--%>
                <%--</li>--%>
                <li class="bordercolor clearfix">
                    <span style="border-bottom: 1px solid #fff;">整改时限</span>
                    <label style="width: 30%;">
                        <input type="text" name="reformtime" placeholder="请填写整改时限"" style="background: #fcfcfc;    width: 80%;
    float: none;
    margin-top: 0px;">
                    </label>
                    <span style="border-bottom: 1px solid #fff;">整改责任人</span>
                    <label style="width: 27%;">
                        <input type="text" name="reformuser" placeholder="请填写整改责任人" style="background: #fcfcfc;    width: 100%;
    float: none;
    margin-top: 0px;">
                    </label>
                </li>
                <li class="bordercolor clearfix">
                    <span style="border-bottom: 1px solid #fff;height: 144px;line-height: 144px">整改措施</span>
                    <label style="width: 80%;height: 144px;">
                        <textarea name="reformtype" style="background: #fcfcfc"  placeholder="请填写整改措施"></textarea>
                    </label>
                </li>

                <li class="bordercolor clearfix">
                    <span style="border-bottom: 1px solid #fff;height: 100px;line-height: 100px">整改后照片</span>
                    <label style="width: 80%;height: 100px;">
                        <div class="picture nextTwo">
                            <input type="hidden" name="attachmentIdAfter">
                            <img class="fl addPhotos" style="    width: 60px;cursor: pointer;
    height: 60px;
    margin-top: 4px;
    margin-right: 7px;" src="/img/grid/addtupin.png" alt="添加照片">



                            <input type="hidden" name="attachmentNameAfter">
                            <ul class="fl" style="width:84%">
                                <li>
                                    <img src="/img/app/email.png" alt="">
                                    <b class="deleClear">x</b>
                                </li>
                            </ul>



                        </div>
                    </label>
                </li>
                <%--<li class="bordercolor clearfix">--%>
                    <%--<span style="border-bottom: 1px solid #fff;height: 144px;line-height: 144px">备注</span>--%>
                    <%--<label style="width: 80%;height: 144px;">--%>


                        <%--<textarea name="mark" id=""  placeholder="请填写备注" style="background: #fcfcfc"></textarea>--%>
                    <%--</label>--%>
                <%--</li>--%>
                <%--<li class="bordercolor clearfix">--%>
                <%--<span style="border-bottom: 1px solid #fff;height: 70px;line-height: 70px">巡检人员签字</span>--%>
                <%--<label style="width: 80%;height: 70px;">--%>
                <%--<textarea style="height: 40px;margin-top: 8px;" name="" id=""  placeholder="巡检人员请签字" style="background: #f9f9f9"></textarea>--%>
                <%--</label>--%>
                <%--</li>--%>

            </ul>
            <div style="height: 88px;line-height: 88px;text-align: center">
                <a href="javascript:void (0)" class="preservation" style="
                margin-top: 25px;display: inline-block;margin-right: 10px;
                line-height: 1;font-size:18px;padding: 8px 20px;
                background: #2F8AE3;color: #fff;border-radius: 6px">保存</a>
                <a href="javascript:void (0)" class="getBack"  style="
                margin-top: 25px;display: inline-block;
                line-height: 1;font-size:18px;padding: 8px 20px;background: #2F8AE3;color: #fff;border-radius: 6px">返回</a>
                <%--<a href="javascript:void (0)" class="shangbao"  style="--%>
                <%--margin-top: 25px;display: inline-block;    margin-left: 12px;--%>
                <%--line-height: 1;font-size:18px;padding: 8px 20px;background: #2F8AE3;color: #fff;border-radius: 6px">上报</a>--%>

            </div>
        </div>
    </form>
</div>



<div class="mainData" >
    <div style="margin: 0 auto;margin-top: 46px;height: 60px;width: 97%;" class="clearfix">
        <label class="fl" style="margin-top: 16px;">
            <%--<span class="fl" style="margin-top: 5px;">检查类型：</span>--%>
            <input type="text" class="info" placeholder="网格名称">
            <%--<select name="checkType1" id="checkType1">
                <option value="">请选择</option>
            </select>--%>
        </label>
        <label class="fl" style="margin-top: 16px;">
            <button type="button" class="Query fl">查询</button>
        </label>

    </div>
    <div class="pagediv" style="margin: 0 auto;width: 97%;">
        <table>
            <thead>
            <tr>
                <th>序号</th>
                <th>网格名称</th>
                <th>检查人员姓名</th>
                <th>检查时间</th>
                <th>检查单位名称</th>
                <th>隐患级别</th>
                <th>整改情况</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>
</div>
<div id="dbgz_page" class="M-box3 fr" style="display: none;"></div>

<script>
    /**
     * Created by 骆鹏 on 2017/9/11.
     */


    function validform() {//验证方法
        return  $("#datasave").validate({
            checkStart: true,
            focusInvalid: false,
            errorPlacement: function (error, element) { //错误信息位置设置方法
                layer.tips(error[0].innerText, $(element), {time: 2000, tipsMore: true});
            },
            rules: {//验证那个东西
                subCommunity:{
                    required:true
                },
                checkTime:{
                    required:true
                },
                checkType:{
                    required:true
                },
                gridId:{
                    required:true
                }
            },
            messages: {//提示信息
                subCommunity:{
                    required:'该项为必填项'
                },
                checkTime:{
                    required:'该项为必填项'
                },
                checkType:{
                    required:'该项为必填项'
                },
                gridId:{
                    required:'该项为必填项'
                }
            }
        })
    }


    function ajaxData(url,num){
        $('#datasave').prop('action',url)
        $('[name="userId"]').val($.cookie('userId'))

        var attIdLen=$('.prevTwo .hiddenId').length;
        var attNameLen=$('.prevTwo .hiddenName').length;
        var attId="";
        var attName="";
        for(var i=0;i<attIdLen;i++){
            attId += $('.prevTwo .hiddenId').eq(i).attr('value')+','
        }
        for(var i=0;i<attNameLen;i++){
            attName += $('.prevTwo .hiddenName').eq(i).attr('value')+'*'
        }
        $('input[name="attachmentIdBefore"]').val(attId)//图片id1
        $('input[name="attachmentNameBefore"]').val(attName)//图片名称1

        var attIdLen2=$('.nextTwo .hiddenId').length;
        var attNameLen2=$('.nextTwo .hiddenName').length;
        var attId2="";
        var attName2="";
        for(var i=0;i<attIdLen2;i++){
            attId2 += $('.nextTwo .hiddenId').eq(i).attr('value')+','
        }
        for(var i=0;i<attNameLen2;i++){
            attName2 += $('.nextTwo .hiddenName').eq(i).attr('value')+'*'
        }
        $('input[name="attachmentIdAfter"]').val(attId2)//图片id2
        $('input[name="attachmentNameAfter"]').val(attName2)//图片名称2


        $('#datasave').ajaxSubmit({
            type:'post',
            dataType:'json',
            success:function (json) {
                if(json.flag) {
                    $.layerMsg({content:'操作成功',icon:1},function () {
                        $('.mainBg').hide();
                        $('.mainData').show();
                        $('.newBtn').show()
                        $('.shangbao').show()
                        ajaxPage.data.page=1;
                        ajaxPage.page();
                    });
                    if(num==1){
                        parent.hrefOpen(json.data.said)
                    }

                }else {
                    alert('异常')
                }

            }
        })
    }


    function subCommunityTwo(me) {
        $.get('/gridInfo/gridSettingsTree',{deptId:$(me).val(),typeId:$(me).val()},function (json) {
            if(json.flag){
                var str='<option value="">请选择</option>';
                for(var i=0;i<json.obj.length;i++){
                    str+='<option value="'+json.obj[i].gridId+'">'+json.obj[i].gridName+'</option>'
                }
                $('[name="gridId"]').html(str)
            }

        },'json')
    }

    function filesTwo(mes) {
        var arr=mes.files;
        var bool=true;
        for(var i=0;i<arr.length;i++){
            if(arr[i].name.indexOf('.png')==-1&&arr[i].name.indexOf('.jpg')==-1&&arr[i].name.indexOf('.PNG')==-1&&arr[i].name.indexOf('.JPG')==-1){
                bool=false;
                break;
            }
        }
        if(!bool){
            $.layerMsg({content:'只能上传.png或.jpg格式！',icon:2});
            return
        }
        $('#datasave').prop('action','/flow/fileUpload?module=parameter')

        $('#datasave').ajaxSubmit({
            type:'post',
            dataType:'json',
            success:function (json) {
                if(json.flag) {
                    var str='';
                    var arr=json.datas;
                    var attStrId='';
                    var attStrName='';
                    for(var i=0;i<arr.length;i++){

                        attStrId+=arr[i].attStrId+',';
                        attStrName+=arr[i].attStrName+'*';
                        str+='<li class="pic">' +
                            '<img src="/xs?'+arr[i].attUrl+'" alt="">' +
                            '<b class="deleClear">x</b>' +
                            '<input type="hidden" class="hiddenId" name="attachmentNameIds" value="'+arr[i].attStrId+'">' +//id
                            '<input type="hidden" class="hiddenName"  name="attachmentNametwo" value="'+arr[i].attStrName+'">' +//名字
                            '</li>'
                    }
                    $(me).siblings('ul').append(str)
                    $(me).prev().val(attStrId)
                    $(me).next().val(attStrName)
                }else {
                    alert('异常')
                }

            }
        })

    }



    function clearData(fn) {
        $('input').each(function (i,n) {

            $(this).val('')


        })
        var arrs=$('.mainBg select option')
        for(var i=0;i<arrs.length;i++){
            if($(arrs[i]).val()==''){
                $(arrs[i]).prop('selected','selected')
            }else {
                $(arrs[i]).removeProp('selected')
            }
        }
        $('textarea').each(function (i,n) {
            $(this).val('')
        })

        $('.picture ul').html('')

        if(fn!=undefined){
            fn()
        }
    }




    function inputHuixian(name,data) {
        if(data==undefined||data==''){
            return
        }
        $('[name="'+name+'"]').val(data)
    }



    function forbidden() {//禁用
        $('input').each(function (i,n) {
            $(this).prop('disabled','disabled')
        })
        $('select').each(function (i,n) {
            $(this).prop('disabled','disabled')
        })
        $('textarea').each(function (i,n) {
            $(this).prop('disabled','disabled')
        })
        $('.addPhotos').hide();
        $('.deleClear').hide();
    }


    function removeForbidden() {//删除禁用
        $('input').each(function (i,n) {
            $(this).removeProp('disabled','disabled')
        })
        $('select').each(function (i,n) {
            $(this).removeProp('disabled','disabled')
        })
        $('textarea').each(function (i,n) {
            $(this).removeProp('disabled','disabled')
        })
        $('.addPhotos').show();
    }

    function selectHuixian(names,data,fn) {
        if(data==undefined||data==''){
            return
        }

        var selectarr= $('[name="'+names+'"]').find('option');
        for(var i=0;i<selectarr.length;i++){
            if($(selectarr[i]).val()==data){
                $(selectarr[i]).prop('selected','selected')
            }else {
                $(selectarr[i]).removeProp('selected')
            }
        }
        if(fn!=undefined){
            fn()
        }

    }


    var me=null;
    var ajaxPage={
        data:{
            page:1,//当前处于第几页
            pageSize:10,//一页显示几条
            exportId:1,
            checkType:null
        },
        page:function () {
            var me=this;
            this.data.checkType=$("#checkType1 ").val();
            $.get('/inspectionrecord/getList',this.data,function (json) {
                if(json.flag){
                    var str='';
                    var arr=json.data;
                    for(var i=0;i<arr.length;i++){
                        str+='<tr>' +
                            '<td>'+(i+1)+'</td>' +
                            '<td><a href="javascript:void(0)" data-id="'+arr[i].said+'"  data-type="2" style="color: #00a0e9;margin-right: 10px" class="btnData checkAll">'+arr[i].gridName+'</a></td>' +
                            '<td>'+function () {
                                if(arr[i].checkusername!=undefined){
                                    return arr[i].checkusername
                                }else {
                                    return ''
                                }
                            }() +'</td>' +
                            '<td>'+function () {
                                if(arr[i].checktime!=undefined){
                                    return getNowFormatDate(arr[i].checktime)
                                }else {
                                    return ''
                                }
                            }() +'</td>' +
                            '<td>'+arr[i].checkunitname+'</td>' +
                            '<td>'+function () {
                                if(arr[i].problemlev!=undefined&&arr[i].problemlev!=0){
                                    return $("#checkIds").find("option[value='"+[arr[i].problemlev]+"']").text()
                                }else {
                                    return ''
                                }
                            }() +'</td>' +
                            '<td>'+function () {
                                if(arr[i].reformsituation!=undefined&&arr[i].reformsituation!=0){
                                    return $("#reformsituation").find("option[value='"+[arr[i].reformsituation]+"']").text()
                                }else {
                                    return ''
                                }
                            }() +'</td>' +
                            '<td>' +
                            /*'<a href="javascript:void(0)" data-id="'+arr[i].said+'"  data-type="2" style="color: #00a0e9;margin-right: 10px" class="btnData checkAll">查看</a>' +*/
                            '<a href="javascript:void(0)" data-id="'+arr[i].said+'"  data-type="3" style="color: #00a0e9;margin-right: 10px" class="btnData checkAll">修改</a>' +
                            '<a href="javascript:void(0)" data-id="'+arr[i].said+'" style="color: #00a0e9" class=" checkAll deleteme">删除</a>' +
                            '</td>' +
                            '</tr>'
                    }
                    $('.pagediv table tbody').html(str)
                    $('.newBtn').show()
                    if(json.total>10){
                        $('#dbgz_page').show();
                        me.pageTwo(json.total,me.data.pageSize,me.data.page)
                    }else{
                        $('#dbgz_page').hide();
                    }

                }
            },'json')


        },
        pageTwo:function (totalData, pageSize,indexs) {
            var mes=this;
            $('#dbgz_page').pagination({
                totalData: totalData,
                showData: pageSize,
                jump: true,
                coping: true,
                homePage:'',
                endPage: '',
                current:indexs||1,
                callback: function (index) {

                    mes.data.page=index.getCurrent();
                    mes.page();
                }
            });
        }
    }

    $(function () {
        ajaxPage.page();



        var time = {
            elem:'#time',
            format:'YYYY-MM-DD hh:mm:ss',
            min:laydate.now(),
            max:'2999-12-31 23:59:59',
            istime:true,//是否显示时分秒
            istoday:true,//是否显示【今天】的按钮
            isclear:true,//是否显示【清空】的按钮
            festival: true,//是否显示节日
            start: laydate.now(0,"YYYY-MM-DD hh:mm:ss"),  // 开始日期
            fixed: false,   // 是否固定在可视区域
            zIndex: 10000,  // css控制图层的遮罩效果（效果不明显）
            ready: function(dates){  // 选择好日期的回调
                console.log(dates)
            }
        }
        laydate(time);
        $('#time').val(laydate.now(0, 'YYYY-MM-DD hh:mm:ss'));



        $.get('/code/getCode?parentNo=GRID_CHECK',function (json) {
            if(json.flag){
                var str='<option value="">请选择</option>';
                for(var i=0;i<json.obj.length;i++){
                    str+='<option value="'+json.obj[i].codeNo+'">'+json.obj[i].codeName+'</option>'
                }
                $('#said').html(str)
                $('[name="checkType1"]').html(str)

            }
        },'json')
        $.get('/gridInfo/gridSettingsTree?deptId=1&typeId=1',function (json) {//一级网格
            if(json.flag){
                var str='<option value="">请选择</option>';
                for(var i=0;i<json.obj.length;i++){
                    str+='<option value="'+json.obj[i].gridId+'">'+json.obj[i].gridName+'</option>'
                }
                $('#subCommunity').html(str)
            }
        },'json')








        // $.get('/gridInfo/gridSettingsList',function (json) {
        //     if(json.flag){
        //         var str='<option value="">请选择</option>';
        //         for(var i=0;i<json.datas.length;i++){
        //             str+='<option value="'+json.datas[i].gridId+'">'+json.datas[i].gridName+'</option>'
        //         }
        //         $('[name="gridId"]').html(str)
        //     }
        // },'json')


        $('.getBack').click(function () {
            $('.mainBg').hide();
            $('.mainData').show();
            $('.newBtn').show();

            $('.shangbao').show();
            $('#dbgz_page').show();

            removeForbidden();
        })

        $(document).delegate('.deleteme','click',function (i,n) {
            var $id=$(this).attr('data-id');
            $.layerConfirm({title:'确定删除',content:'您确定要删除吗？',icon:0},function(){
                $.get('/inspectionrecord/deleteRecord',{id:$id},function (json) {
                    $.layerMsg({content:'删除成功！',icon:1},function(){
                        location.reload();
                    });
                },'json')
            })
        })





        $('.shangbao').click(function () {
            if(validform().form()) {
                if($('#subCommunity').val()==''){
                    layer.msg('社区名称不能为空', { icon:6});
                    return false;
                }
                if($('#checkIds').val()==''){
                    layer.msg('隐患级别不能为空', { icon:6});
                    return false;
                }
                if($('#reformsituation').val()==''){
                    layer.msg('整改情况不能为空', { icon:6});
                    return false;
                }
                ajaxData($('.preservation').attr('data-url'), 1)
            }

        })




        $(document).delegate('.btnData','click',function () {
            var $type=$(this).attr('data-type');
            var said=$(this).attr('data-id');
            $('.mainBg').show();
            $('.mainData').hide();
            // $('.cont').hide();
            if($type==1){
                $('.preservation').show()
//                $('.preservation').text('新建')
                clearData()
                $('.preservation').attr('data-url','/inspectionrecord/addRecord')
                $('[name="said"]').val(said)
                $('.newBtn').hide()
                $('#time').val(laydate.now(0, 'YYYY-MM-DD hh:mm:ss'));
                $('#dbgz_page').hide();

            }else if($type==2){
                $('.preservation').hide()
                $('.shangbao').hide()
                $('#dbgz_page').hide();

                $('[name="gridId"]').html('<option value="">请选择</option>')
                $('.newBtn').hide()
                clearData(function () {
                    $.get('/inspectionrecord/getRecordsById',{id:said},function (json) {

                        if(json.flag){
                            var jsongridId=json;
                            selectHuixian('areaname',json.data.areaname,function () {
                                $.get('/gridInfo/gridSettingsTree',{deptId:$('[name="areaname"]').val(),typeId:$('[name="areaname"]').val()},function (json) {
                                    if(json.flag){

                                        var str='<option value="">请选择</option>';
                                        for(var i=0;i<json.obj.length;i++){
                                            str+='<option value="'+json.obj[i].gridId+'">'+json.obj[i].gridName+'</option>'
                                        }
                                        $('[name="gridId"]').html(str)
                                        selectHuixian('gridId',jsongridId.data.gridId)
                                    }

                                },'json')
                            })


                            inputHuixian('checkusername',json.data.checkusername)
                            inputHuixian('checktime',getNowFormatDate(json.data.checktime))
                            selectHuixian('problemlev',json.data.problemlev)
                            selectHuixian('reformsituation',json.data.reformsituation)
                            inputHuixian('checkunitname',json.data.checkunitname)
                            inputHuixian('problemdes',json.data.problemdes)
                            inputHuixian('reformtime',json.data.reformtime)
                            inputHuixian('reformuser',json.data.reformuser)
                            inputHuixian('reformtype',json.data.reformtype)
                            /*inputHuixian('attachmentName',json.data.attachmentName)
                            inputHuixian('attachmentName2',json.data.attachmentName2)*/
                            var arr=json.data.attachmentListBefore;
                            $('[name="said"]').val(said)
                            var str='';
                            for(var i=0;i<arr.length;i++){
                                str+='<li class="pic">' +
                                    '<img src="/xs?'+arr[i].attUrl+'" alt="">' +
                                    '<b class="deleClear">x</b>' +
                                    '<input type="hidden" class="hiddenId" name="attachmentNameIds" value="'+arr[i].aid+'@'+arr[i].ym+'_'+arr[i].attachId+'">' +//id
                                    '<input type="hidden" class="hiddenName" name="attachmentNametwo" value="'+arr[i].attachName+'">' +//名字
                                    '</li>'
                            }

                            $('.prevTwo>ul').html(str);
                            var attTwo=json.data.attachmentListAfter;
                            var strTwo='';
                            for(var i=0;i<attTwo.length;i++){
                                strTwo+='<li class="pic">' +
                                    '<img src="/xs?'+attTwo[i].attUrl+'" alt="">' +
                                    '<b class="deleClear">x</b>' +
                                    '<input type="hidden" class="hiddenId" name="attachmentNameIds" value="'+attTwo[i].aid+'@'+attTwo[i].ym+'_'+attTwo[i].attachId+'">' +//id
                                    '<input type="hidden" class="hiddenName" name="attachmentNametwo" value="'+attTwo[i].attachName+'">' +//名字
                                    '</li>'
                            }
                            $('.nextTwo>ul').html(strTwo);
                            forbidden()
                        }
                    },'json')
                })
            }else if($type==3){
                $('.newBtn').hide()
                $('#dbgz_page').hide();
                $('.preservation').show()
                $('.preservation').text('保存')
                $('.preservation').attr('data-url','/inspectionrecord/updateRecord')
                $('[name="gridId"]').html('<option value="">请选择</option>')
                clearData(function () {
                    $.get('/inspectionrecord/getRecordsById',{id:said},function (json) {
                        if(json.flag){
                            $('[name="said"]').val(said)
                            var jsongridId=json;
                            // inputHuixian('subCommunity',json.data.subCommunity)
                            selectHuixian('areaname',json.data.areaname,function () {
                                $.get('/gridInfo/gridSettingsTree',{deptId:$('[name="areaname"]').val(),typeId:$('[name="areaname"]').val()},function (json) {
                                    if(json.flag){
                                        var str='<option value="">请选择</option>';
                                        for(var i=0;i<json.obj.length;i++){
                                            str+='<option value="'+json.obj[i].gridId+'">'+json.obj[i].gridName+'</option>'
                                        }
                                        $('[name="gridId"]').html(str)
                                        selectHuixian('gridId',jsongridId.data.gridId)
                                    }

                                },'json')
                            })





                            inputHuixian('checkusername',json.data.checkusername)
                            inputHuixian('checktime',getNowFormatDate(json.data.checktime))
                            selectHuixian('problemlev',json.data.problemlev)
                            selectHuixian('reformsituation',json.data.reformsituation)
                            inputHuixian('checkunitname',json.data.checkunitname)
                            inputHuixian('problemdes',json.data.problemdes)
                            inputHuixian('reformtime',json.data.reformtime)
                            inputHuixian('reformuser',json.data.reformuser)
                            inputHuixian('reformtype',json.data.reformtype)
                            var arr=json.data.attachmentListBefore;
                            var str='';
                            for(var i=0;i<arr.length;i++){
                                str+='<li class="pic">' +
                                    '<img src="/xs?'+arr[i].attUrl+'" alt="">' +
                                    '<b class="deleClear">x</b>' +
                                    '<input type="hidden" class="hiddenId" name="attachmentNameIds" value="'+arr[i].aid+'@'+arr[i].ym+'_'+arr[i].attachId+'">' +//id
                                    '<input type="hidden" class="hiddenName" name="attachmentNametwo" value="'+arr[i].attachName+'">' +//名字
                                    '</li>'
                            }
                            $('.prevTwo>ul').html(str);
                            var attTwo=json.data.attachmentListAfter;
                            var strTwo='';
                            for(var i=0;i<attTwo.length;i++){
                                strTwo+='<li class="pic">' +
                                    '<img src="/xs?'+attTwo[i].attUrl+'" alt="">' +
                                    '<b class="deleClear">x</b>' +
                                    '<input type="hidden" class="hiddenId" name="attachmentNameIds" value="'+attTwo[i].aid+'@'+attTwo[i].ym+'_'+attTwo[i].attachId+'">' +//id
                                    '<input type="hidden" class="hiddenName" name="attachmentNametwo" value="'+attTwo[i].attachName+'">' +//名字
                                    '</li>'
                            }
                            $('.nextTwo>ul').html(strTwo);

                        }
                    },'json')
                })
            }
        })


        $(document).delegate('.preservation','click',function () {
            if(validform().form()) {
                if($('#subCommunity').val()==''){
                    layer.msg('社区名称不能为空', { icon:6});
                    return false;
                }
                if($('#checkIds').val()==''){
                    layer.msg('隐患级别不能为空', { icon:6});
                    return false;
                }
                if($('#reformsituation').val()==''){
                    layer.msg('整改情况不能为空', { icon:6});
                    return false;
                }
                ajaxData($(this).attr('data-url'))
            }
        })



        $(document).delegate('.deleClear','click',function () {
            $(this).parent().remove()
        })

        $('.addPhotos').click(function () {
            me=this;
            $('[name="file"]').click()
        })

        $('.Query').click(function () {
            ajaxPage.data.subCounty=$('.info').val();;
            ajaxPage.page();
        })

        $(document).on('click','.pic img',function () {
            var imgg=$(this).get(0)
            var imgs=$(this).attr('src')
            var wt=(document.documentElement.clientWidth || document.body.clientWidth);
            var ht=(document.documentElement.clientHeight || document.body.clientHeight);
            console.log(wt)
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area:[wt+'px',ht+'px'],
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content:
//                '<img src="'+imgs+'" width="'+wt+'" height="'+ht+'">'
                '<div class="bigImg"  style="width: '+(wt-20)+'px;height:'+ht+'px;text-align: center">' +
                '<img style="margin-top:150px" src="'+imgs+'" style="width:'+function () {
                    if((wt)*0.8>imgg.naturalWidth) {
                        return imgg.naturalWidth
                    }else {
                        return (wt)*0.8
                    }
                }()+'px;height:'+function () {
                    if((ht)*0.8>imgg.naturalHeight) {
                        return imgg.naturalHeight
                    }else {
                        return (ht)*0.8
                    }
                }()+'px">' +
                '</div>',
                success:function(){

                }
            });

        })

        $(document).on('click','.layui-layer-content',function () {
            layer.closeAll()
        })

    })
    function getNowFormatDate(tm) {
        var date = new Date(tm);
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        var Hours = date.getHours();
        var Minutes = date.getMinutes();
        var Seconds = date.getSeconds();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        if (Hours >= 0 && Hours <= 9) {
            Hours = "0" + Hours;
        }
        if (Minutes >= 0 && Minutes <= 9) {
            Minutes = "0" + Minutes;
        }
        if (Seconds >= 0 && Seconds <= 9) {
            Seconds = "0" + Seconds;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
            ' ' + Hours + seperator2 + Minutes +
            seperator2 + Seconds;
        return currentdate;
    }
</script>
</body>

</html>